# 记住喜欢的数
# 将练习10-11中的程序合二为一

import json


def get_favourite_number():
    try:
        with open('favourite_number.json') as f:
            return json.load(f)
    except FileNotFoundError:
        return None


def set_favourite_number():
    num = input("What is your favourite number? ")
    with open('favourite_number.json', 'w') as f:
        json.dump(num, f)
    return num


def func_favourite_number():
    favourite_number = get_favourite_number()
    if favourite_number:
        print(f"I know your favourite number! It's {favourite_number}.")
    else:
        favourite_number = set_favourite_number()
        print(f"Your favourite num is {favourite_number}.")


func_favourite_number()
